package com.jiangnan.artstudio.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.jiangnan.artstudio.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class EventMessageFragment extends BaseFragment {
    private ListView listView;
    private Button returnBtn;
    private EventFragment ef;
    private SimpleAdapter adapter;
    private List<Map<String,Object>> dataList;
    private int[] icon={R.drawable.head1,R.drawable.head2,R.drawable.head3,R.drawable.head4,R.drawable.head5};
    private String[] iconName = {"BOBBY","金泰亨","李胜勋","Dush hush","Dush hush"};
    private String[] iconMessage = {"你终于找到我啦！","你终于找到我啦！","你终于找到我啦！","你终于找到我啦！","你终于找到我啦！"};
    private String[] iconTime = {"10-6","10-1","9-6","8-5","7-15"};
    private FragmentManager fManager;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_event_message,container,false);

        findViewId(view);
        fManager = getFragmentManager();
        dataList=new ArrayList<>();
        adapter=new SimpleAdapter(getActivity(),getData(),R.layout.list_event_messeage,
                new String[]{"img","name","time","messeage"},
                new int[]{R.id.message_head,R.id.message_name,R.id.message_time,R.id.message_messeage});

        listView.setAdapter(adapter);

        // 沉浸式状态栏
        initTitle(view);

        //状态栏字体变黑
        getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);

        onClick();

        return view;
    }

    public void hideAllFragment(FragmentTransaction fragmentTransaction) {
        if(ef != null) fragmentTransaction.hide(ef);
    }

    public void onClick() {
        returnBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                // 先将状态栏字体色重新改回白色
                getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

                FragmentTransaction fTransaction = fManager.beginTransaction();
                hideAllFragment(fTransaction);
                ef = new EventFragment();
                fTransaction.add(R.id.main_content,ef).commit();
            }
        });
    }

    public List<Map<String,Object>> getData(){
        for(int i=0;i<icon.length;i++){
            Map<String,Object>map=new HashMap<>();
            map.put("img",icon[i]);
            map.put("name",iconName[i]);
            map.put("time",iconTime[i]);
            map.put("messeage",iconMessage[i]);
            dataList.add(map);
        }
        return dataList;
    }

    public void findViewId(View view) {
        listView = view.findViewById(R.id.messeage_list);
        returnBtn = view.findViewById(R.id.messeage_return);
    }
}
